﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ServirMovil.Clases.Movil;
using GS1.Library;

namespace ServirMovil.Formulario
{
    public partial class frmPresentacion : Form
    {
        #region --- Variables y constantes ---
        private int barwidth = Screen.PrimaryScreen.Bounds.Width - 65;
        //private Bitmap backgroundBmp = null;

        #endregion

        #region --- Constructor ---
        public frmPresentacion()
        {
            InitializeComponent();
        }
        #endregion

        #region --- Eventos Formulario ---
        private void frmPresentacion_Load(object sender, EventArgs e)
        {
            cargarFormulario();
        }

        private void tmrCarga_Tick(object sender, EventArgs e)
        {
            this.tmrCarga.Enabled = false;

            frmLogin frmLogin = null;
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                //Carga de Parametros Generales
                //------------------------------------------------------------
                //Setear Configuracion regional y Zona Horaria
                Util.CambiarConfiguracionRegional(Registry.CONFIG_PAIS.LCID_PERU);
                mostrarProgreso(30);

                //Carga de Parametros Generales
                if (Util.VerificaCultura(false, false, true) == false)
                {
                    salir();
                    return;
                }
                mostrarProgreso(40);

                // Instanciando teclado virtual
                ParametrosAplicacion.TECLADO = new GS1.SipExv();

                mostrarProgreso(70);
                // Cargar Parametros de Configuracion
                MetodosAplicacion.leerXML();
                //------------------------------------------------------------
                mostrarProgreso(100);
                //Fin de Carga

                Cursor.Current = Cursors.Default;

                frmLogin = new frmLogin();
                frmLogin.ShowDialog();

                salir();
            }
            catch (Exception ex)
            {
                Util.MensajeError(ex, this.Text);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                if (frmLogin != null) frmLogin.Dispose();
                frmLogin = null;
            }
        }
        #endregion

        #region --- Metodos Propios ---
        private void cargarFormulario()
        {
            MetodosAplicacion.configuraFormulario(this);
            this.picLogo.Show();
            this.tmrCarga.Interval = 1000;
            this.tmrCarga.Enabled = true;

            this.picLogo.Width = Screen.PrimaryScreen.Bounds.Width - 70;
            this.picLogo.SizeMode = PictureBoxSizeMode.StretchImage;
            this.picLogo.Refresh();
        }

        private void salir()
        {
            this.Close();
        }

        private void mostrarProgreso(int porcentaje)
        {
            int iPosX = (Screen.PrimaryScreen.Bounds.Width - barwidth) / 2; //32
            int iPosY = Screen.PrimaryScreen.Bounds.Height - 120; //120
            int iHeight = 12;
            Graphics gr = this.CreateGraphics();

            gr.DrawRectangle(new Pen(Color.Black), new Rectangle(iPosX, iPosY, barwidth, iHeight));
            gr.FillRectangle(new SolidBrush(Color.FromArgb(0, 192, 0)), new Rectangle(iPosX, iPosY, (barwidth * porcentaje) / 100, iHeight));

        }
        #endregion
    }
}